<?php
class Graph {
  var $uri;
  var $credentials;
  var $request_factory;

  function Graph($uri, $credentials = null)  {
    $this->uri = $uri;
    $this->credentials = $credentials;
  }

  function apply_changeset($cs) {
    return $this->apply_changeset_rdfxml( $cs->to_rdfxml());
  }

  function apply_changeset_rdfxml($rdfxml) {
    if (! isset( $this->request_factory) ) {
      $this->request_factory = new HttpRequestFactory();
    }

    $uri = $this->uri;

    $request = $this->request_factory->make( 'POST', $uri);
    $request->set_accept("*/*");
    $request->set_content_type("application/vnd.talis.changeset+xml");
    $request->set_body( $rdfxml );
    if  ($this->credentials != null) {
      $request->set_auth( $this->credentials->get_full_update_auth() );
    }

    return $request->execute();
  }

  function apply_versioned_changeset_rdfxml($rdfxml) {
    if (! isset( $this->request_factory) ) {
      $this->request_factory = new HttpRequestFactory();
    }

    $uri = $this->uri . '/changesets';

    $request = $this->request_factory->make( 'POST', $uri);
    $request->set_accept("*/*");
    $request->set_content_type("application/vnd.talis.changeset+xml");
    $request->set_body( $rdfxml );
    if  ($this->credentials != null) {
      $request->set_auth( $this->get_apply_versioned_changeset_auth() );
    }

    return $request->execute();
  }

  function submit_rdfxml($rdfxml) {
    if (! isset( $this->request_factory) ) {
      $this->request_factory = new HttpRequestFactory();
    }

  	$uri = $this->uri;
    $request = $this->request_factory->make( 'POST', $uri);
    $request->set_content_type("application/rdf+xml");
    $request->set_accept("*/*");
    $request->set_body( $rdfxml );
    if  ($this->credentials != null) {
      $request->set_auth( $this->credentials->get_full_update_auth() );
    }
    return $request->execute();
  }

  function get_apply_versioned_changeset_auth() {
    // to be overridden
  }
}
?>